﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wjtour.Common;
using Hjp.FrameWork.Common;
using Wjtour.BLL;

namespace Wjtour.Web.Front
{
    public partial class login : BasePage
    {

        protected TextBox account;
        protected TextBox pwd;
        protected TextBox code;
        protected Button btnlogin;

        protected void Page_Load(object sender, EventArgs e)
        {
            btnlogin.Click += btnlogin_Click;
        }

        void btnlogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(account.Text))
            {
                Utils.Alert(this.Page, "邮箱地址不能为空！");
                return;
            }
            if (string.IsNullOrWhiteSpace(pwd.Text))
            {
                Utils.Alert(this.Page, "密码不能为空！");
                return;
            }
            if (string.IsNullOrWhiteSpace(code.Text))
            {
                Utils.Alert(this.Page, "验证码不能为空！");
                return;
            }
            if (code.Text.ToUpper() != Session["CheckCode"].ToString())
            {
                Utils.Alert(this.Page, "验证码输入不正确！");
                return;
            }

            Wjtour.BLL.member_bll m_bll = new member_bll();
            Wjtour.Domain.member member = m_bll.CheckEmail(account.Text.Trim());
            if (member == null)
            {
                Utils.Alert(this.Page, "该邮箱没有注册过！");
                return;
            }
            member = m_bll.Login(account.Text.Trim(), pwd.Text.Trim());
            if (member == null)
            {
                Utils.Alert(this.Page, "密码出错！");
                return;
            }
            else
            {
                Session["CurrentMember"] = member;
                Response.Redirect("memberinfoedit.aspx");
            }
        }
    }
}
